package com.ponxu.mb.web.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ponxu.log.Log;
import com.ponxu.log.LogFactory;
import com.ponxu.mb.Global;
import com.ponxu.mb.service.OptionService;
import com.ponxu.mb.web.BlogObject;
import com.ponxu.utils.Lang;
import com.ponxu.web.core.Action;
import com.ponxu.web.core.WebContext;

/**
 * @author xwz
 * 
 */
public abstract class MiniBlogAction extends Action {
	private static final Log LOG = LogFactory.getLog();

	// 常量
	protected static final String FTL_404 = "404.ftl";

	@Override
	public String after(HttpServletRequest request,
			HttpServletResponse response, String result)
			throws ServletException, IOException {
		WebContext context = new WebContext(request, response);

		String theme = Lang.defaultString(OptionService.read("theme"),
				Global.read("DEFAULT_THEME"));
		String themePath = "/themes/" + theme;
		context.put("theme", theme);
		context.put("themePath", themePath);
		context.put("blog", BlogObject.getInstance());

		if (result == null) {
			return result;
		}

		String ftl = result;
		if (!result.startsWith("/")) {
			ftl = themePath + "/" + result;
		}
		LOG.debug("ftl: %s", ftl);
		return ftl;
	}

}
